package com.linxz.wandnroid.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.linxz.wandnroid.R;
import com.linxz.wandnroid.pojo.WanAndroidArticleBean;

import java.util.List;

/**
 * @author Linxz
 * 创建日期：2020年02月21日 17:37
 * version：v4.5.4
 * 描述：
 */
public class ArticleAdapter extends BaseQuickAdapter<WanAndroidArticleBean, BaseViewHolder> {

    private boolean hasHeaderView;

    public void setHasHeaderView(boolean hasHeaderView){
        this.hasHeaderView=hasHeaderView;
    }
    public boolean isHasHeaderView() {
        return hasHeaderView;
    }

    public ArticleAdapter(List<WanAndroidArticleBean> data) {
        super(R.layout.wandroid_item_article,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final WanAndroidArticleBean item) {
        String tip="";
        if (item.getType()==1){
            tip="置顶";
        }else if (item.isFresh()){
            tip="最新";
        }

        helper.setText(R.id.tvTittle, item.getTitle())
                .setText(R.id.tvAuthor, item.getSafeAuthor())
                .setText(R.id.tvDate, item.getSafeDate())
                .setText(R.id.tvLabel, item.getSuperChapterName())
                .setGone(R.id.tvUp, item.getType() == 1 || item.isFresh())
                .setText(R.id.tvUp, tip);

        helper.getView(R.id.itemMain).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClickListener!=null){
                    mOnItemClickListener.onClick(item);
                }
            }
        });

        helper.getView(R.id.itemMain).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (mOnItemClickListener!=null){
                    mOnItemClickListener.onLongClick(item);
                }
                return false;
            }
        });

    }

    private OnItemClickListener mOnItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.mOnItemClickListener=onItemClickListener;
    }
    public interface OnItemClickListener{
        void onClick(WanAndroidArticleBean item);
        void onLongClick(WanAndroidArticleBean item);
    }
}
